package com.shijie;

import javax.servlet.MultipartConfigElement;

import org.apache.catalina.connector.Connector;
import org.apache.coyote.http11.Http11NioProtocol;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.util.Base64Utils;
import org.springframework.util.FileCopyUtils;

import java.io.File;
import java.io.IOException;

@SpringBootApplication
@ComponentScan("com.shijie")
public class Application {

    private final static String KEYSTORE_TEST ="/u3+7QAAAAIAAAABAAAAAQAPd3gucGlub3NlZ24uY29tAAABaE8qyS8AAAUBMIIE/TAOBgorBgEE" +
            "ASoCEQEBBQAEggTpaMjmB5xomynKFg/sFOHgjApB1jOYc696ghNpRYlqRDc//zJCmj5JEnaTMxvg" +
            "OSjNCuKzYPuXi/Rwl7tq329/ZrfSseUSNp+1NLA2yzv7Mm8tf9ImWrdlB5c16G3TGeFlwaWR7jZi" +
            "+JH+iXyb/3+QgmYMJll/dkXIU4s/Ri0cW9Nv+T6+0ZrK57LVTqclbtz/sS63tLC9eW4svE88sIte" +
            "QAuOujGGkkYklwHAvACESPUwAK+XaA7F9sdSrgQ/j8tRp0Po7pc4950Df3Y+BUvbYDOqt/LbC6TH" +
            "dJc3dhtg2UbJfuLeNR9busfkpsSprHxpFXqw590p3Bo14TFwpwycrVJ4aENrRuVsE/KsgYq4KuRT" +
            "gUVFuckVyPHBi9ZxxmYsQl+k9hapiZWbRg8EVnGNFv0qJU0V2Wt/kRjFMnvXfaNBHYNuBcuRECH0" +
            "4b7PcsNpc+9I6gIF5rd75wwY0g9oi0dBPRhNPLCL9hMmDbzRKwT1b6brbmelq6WvCU3nYHp8faC7" +
            "kO0Nn1wetj1/mFBXnEnGNXYFCXMMPY8L1umkVs98ACHwLM31MPthDuK7az4YyYitse8NwrEHxw2H" +
            "7C94ssMCGhNLSkBdTPWHR34ssQBYzdpbiyFEdEqUQsUFThvOQzL7AUd22IFVlweyUaoVJS0/wxS9" +
            "6M4g2HfUAiU1FlWhUmOpAx/Z7lQQBzUOxAom6dxzoiuRb08L5EuUSruXevxREmHRPN0F5zkxu7Og" +
            "Wsw8tP+og/uWFjcyMJYtCkldPOlvrUXYnvmx8fmJCi/qOcMW6QTwM7ZIEuwVW7yHSeRg7guPcewO" +
            "az1zJzF1TyzmrrycHjGNrWR8eG8uq2KQC233nKoCJoYFge3U6bAh/VbTSiGsWANYRCydFILH7Ibe" +
            "GpxxUcAYOv8ZZPMPN5qBoIA1zi3IGXEw75/1O6i2FHm0qEr8Ez+Zc5KkwsE9LF/CYMVqedPniWxf" +
            "+u08KNfOpLqzTK1f+ogTQJIuMHcfzpUjmp4cs1ppmooBf6gZUqa72Fn18vCJANA4ATb03lvMBV6h" +
            "bB61uSNOUX8O2Xk/fYxh4O11bh5idXkogqCj7vhb9TCeFUuJvtlldqf9y85P5Vmaqb3cQlNVcXxZ" +
            "4zumERgCtZvkxyMxfN8B4xj9J7tNGgupupnPEmx7yeU4S+WcwsW4aEdB6OIuRcBDQWF2sEwynoT2" +
            "zOo7jCxDzJ3K8dCYj37AGtHPrZR1EO1P7PxszrsVdXAL5lJZhze2bl8gCw+p4WQVrUnmio7LHaIj" +
            "c6IE1aZEsvu5eThWd1RylQHj37axMjCgrqcok+hjJa6gku0iIOxPvdUuEWa9EVzMfC34rnMTDApT" +
            "Q1FOKyeK9mAtBRXDi5Kd2rK4AEbKUD8duP4qU0t74WEjWBQxLOJpu3bT7or/9FRv9iKb5n3LDDQl" +
            "tgcQ/1NdiumxEUI1XNqvyf6WKN643vYT35q24C8ysVd92d1DfeJykpNxX10G8LFkbaaHPuBPs6mG" +
            "Gpdf7H+R5T+1BLJ1q27E+XMFWddu8a+pDu44HWB2D6ZvTfl8QPsR6VA13y8zfwZC3UaA9NS3g2f+" +
            "auuRNjfueHf3bPZ9N6WCNRoDYUZGXB+8sUpceiKiLdTTBVBgtxq2h76HzkwQFpDWJ4KW19OLa+TS" +
            "slF5ZZpuDiW6jGN6RXxJAAAABAAFWC41MDkAAAWMMIIFiDCCBHCgAwIBAgIQCGDhn8NmQWecKko3" +
            "lMRXoTANBgkqhkiG9w0BAQsFADByMQswCQYDVQQGEwJDTjElMCMGA1UEChMcVHJ1c3RBc2lhIFRl" +
            "Y2hub2xvZ2llcywgSW5jLjEdMBsGA1UECxMURG9tYWluIFZhbGlkYXRlZCBTU0wxHTAbBgNVBAMT" +
            "FFRydXN0QXNpYSBUTFMgUlNBIENBMB4XDTE5MDExNTAwMDAwMFoXDTIwMDExNTEyMDAwMFowGjEY" +
            "MBYGA1UEAxMPd3gucGlub3NlZ24uY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA" +
            "4oyxMpU5WgSwtHJnXmrTR6oxh8sgNbGkK4qK6QnQCJwk6YjefU8HlE6gvO+z8u74zRHI0tVT0GmU" +
            "/ayg4KwoVgQp+/l1ZcZ2yARKUmHq1L98rryy4ok1DrMXRPZZB1hMDnTiYumOlUs8VK60njj9uwfJ" +
            "BZEaoZLxCz/GVl1ofjQKJbN/c/wD3QUISWvtpKbmH7c+ImucC2VsBw7vswLIfmGZ6vRwRjWRNiy3" +
            "70HzYc+kscGd3QVkeSHnNrmlvPw8b5BkvpFQw4LPcpbk6EanczuMXS/iPiHCpq2bvvqpROFTwKJ8" +
            "WbLtAid+QK1ODmTEXlc9shec7EIQSDjn2OVYQwIDAQABo4ICcDCCAmwwHwYDVR0jBBgwFoAUf9OZ" +
            "86BHDjEAVlYijrfMnt3KAYowHQYDVR0OBBYEFPPFbOk+bpjAiLZ6yzS26lVyqubcMBoGA1UdEQQT" +
            "MBGCD3d4LnBpbm9zZWduLmNvbTAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYwFAYIKwYBBQUHAwEG" +
            "CCsGAQUFBwMCMEwGA1UdIARFMEMwNwYJYIZIAYb9bAECMCowKAYIKwYBBQUHAgEWHGh0dHBzOi8v" +
            "d3d3LmRpZ2ljZXJ0LmNvbS9DUFMwCAYGZ4EMAQIBMH0GCCsGAQUFBwEBBHEwbzAhBggrBgEFBQcw" +
            "AYYVaHR0cDovL29jc3AuZGNvY3NwLmNuMEoGCCsGAQUFBzAChj5odHRwOi8vY2FjZXJ0cy5kaWdp" +
            "dGFsY2VydHZhbGlkYXRpb24uY29tL1RydXN0QXNpYVRMU1JTQUNBLmNydDAJBgNVHRMEAjAAMIIB" +
            "BQYKKwYBBAHWeQIEAgSB9gSB8wDxAHcApLkJkLQYWBSHuxOizGdwCjw1mAT5G9+443fNDsgN3BAA" +
            "AAFoTyJVnwAABAMASDBGAiEAx6WA9VhF8jCGp90ZTwHAxBxDKqB1o4FM3itM70UH1bcCIQDgFdsc" +
            "u36wqMnPTAYRehFPqRiDPzE2bq/O1lYvcK1dKgB2AId1v+dZfPiMQ5lfvfNu/1aNR1Y2/0q1YMG0" +
            "6v9eoIMPAAABaE8iVmYAAAQDAEcwRQIhAMA5ld7pOM1M5UIDSD+U55FOdezWqjMqi/I0ubNbX1fV" +
            "AiBQpwCPF6TtnI3lRhlVQoGcGfJHTFfgefeAJtPAXO+bijANBgkqhkiG9w0BAQsFAAOCAQEAAB3/" +
            "vZTcG7eiWCTK352YSePdBGsuNK1sp6jEuopXM9QVATxFcnK6yFPwe9PwtB65Os1yU3YxQhJMBvZB" +
            "7Gd4D0Ynf9MsiB5YtTqqKpx7zSb+wAHoIFwlJWmGtQ6mzL0oTeFe1YoLVaEf8QSCh7NsjxGlMXpj" +
            "XJWti7gwDJvUMA1tDOINyN2s1wqO9iIN6RfBRbUoXFYMDo9SIKzv9mPDgRhf/Li8vXfXRQZF1l7n" +
            "6D3u098JZeaFSbK22l93bktpNWejAg1uQGdnmtyamsCY810uW2M7OJpKVrKIkEQqj4RW/neX44TE" +
            "dI6xgulfFTSAaF1HXHkHAOQFOOGXhadesgAFWC41MDkAAASyMIIErjCCA5agAwIBAgIQBYAmfwby" +
            "lVM0jhwYWl7uLjANBgkqhkiG9w0BAQsFADBhMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNl" +
            "cnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9i" +
            "YWwgUm9vdCBDQTAeFw0xNzEyMDgxMjI4MjZaFw0yNzEyMDgxMjI4MjZaMHIxCzAJBgNVBAYTAkNO" +
            "MSUwIwYDVQQKExxUcnVzdEFzaWEgVGVjaG5vbG9naWVzLCBJbmMuMR0wGwYDVQQLExREb21haW4g" +
            "VmFsaWRhdGVkIFNTTDEdMBsGA1UEAxMUVHJ1c3RBc2lhIFRMUyBSU0EgQ0EwggEiMA0GCSqGSIb3" +
            "DQEBAQUAA4IBDwAwggEKAoIBAQCgWa9X+ph+wAm8Yh1Fk1MjKbQ5QwBOOKVaZR/OfCh+F6f93u7v" +
            "ZHGcUU/lvVGgUQnbzJhR1UV2epJae+m7cxnXIKdD0/VS9btAgwJszGFvwoqXeaCqFoP71wPmXjjU" +
            "wLT70+qvX4hdyYfOJcjeTz5QKtg8zQwxaK9x4JT9CoOmoVdVhEBAiD3DwR5fFgOHDwwGxdJWVBvk" +
            "tnoAzjdTLXDdbSVC5jZ0u8oq9BiTDv7jAlsB5F8aZgvSZDOQeFrwaOTbKWSEInEhnchKZTD1dz6a" +
            "Blk1xGEI5PZWAnVAba/ofH33ktymaTDsE6xRDnW97pDkimCRak6CEbfe3dXw6OV5AgMBAAGjggFP" +
            "MIIBSzAdBgNVHQ4EFgQUf9OZ86BHDjEAVlYijrfMnt3KAYowHwYDVR0jBBgwFoAUA95QNVbRTLtm" +
            "8KPiGxvDl7I90VUwDgYDVR0PAQH/BAQDAgGGMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcD" +
            "AjASBgNVHRMBAf8ECDAGAQH/AgEAMDQGCCsGAQUFBwEBBCgwJjAkBggrBgEFBQcwAYYYaHR0cDov" +
            "L29jc3AuZGlnaWNlcnQuY29tMEIGA1UdHwQ7MDkwN6A1oDOGMWh0dHA6Ly9jcmwzLmRpZ2ljZXJ0" +
            "LmNvbS9EaWdpQ2VydEdsb2JhbFJvb3RDQS5jcmwwTAYDVR0gBEUwQzA3BglghkgBhv1sAQIwKjAo" +
            "BggrBgEFBQcCARYcaHR0cHM6Ly93d3cuZGlnaWNlcnQuY29tL0NQUzAIBgZngQwBAgEwDQYJKoZI" +
            "hvcNAQELBQADggEBAK3dVOj5dlv4MzK2i233lDYvyJ3slFY2X2HKTYGte8nbK6i5/fsDImMYihAk" +
            "p6VaNY/en8WZ5qcrQPVLuJrJDSXT04NnMeZOQDUoj/NHAmdfCBB/h1bZ5OGK6Sf1h5Yx/5wR4f3T" +
            "UoPgGlnU7EuPISLNdMRiDrXntcImDAiRvkh5GJuH4YCVE6XEntqaNIgGkRwxKSgnU3Id3iuFbW9F" +
            "UQ9Qqtb1GX91AJ7i4153TikGgYCdwYkBURD8gSVe8OAco6IfZOYt/TEwii1Ivi1CqnuUlWpsF1Ld" +
            "QNIdfbW3TSe0BhQa7ifbVIfvPWHYOu3rkg1ZeMo6XRU9B4n5VyJYRmEABVguNTA5AAAEZDCCBGAw" +
            "ggNIoAMCAQICEA9bw6F2y3ieICDHiTyBZ7QwDQYJKoZIhvcNAQELBQAwWjELMAkGA1UEBhMCSUUx" +
            "EjAQBgNVBAoTCUJhbHRpbW9yZTETMBEGA1UECxMKQ3liZXJUcnVzdDEiMCAGA1UEAxMZQmFsdGlt" +
            "b3JlIEN5YmVyVHJ1c3QgUm9vdDAeFw0xNjEyMDcxMjE3MzRaFw0yNTA1MTAxMjAwMDBaMGExCzAJ" +
            "BgNVBAYTAlVTMRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j" +
            "b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG9w0BAQEFAAOC" +
            "AQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsBCSDMAZOnTjC3U/dDxGkAV53i" +
            "jSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77u" +
            "KNd0f3p4mVmFaG5cIzJLv07A6Fpt43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvU" +
            "X7Q6hL+hqkpMfT7PT19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM" +
            "1O/4gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo4IBGTCCARUwHQYD" +
            "VR0OBBYEFAPeUDVW0Uy7ZvCj4hsbw5eyPdFVMB8GA1UdIwQYMBaAFOWdWTCCR1jMrPoIVDaGezq1" +
            "BE3wMBIGA1UdEwEB/wQIMAYBAf8CAQEwDgYDVR0PAQH/BAQDAgGGMDQGCCsGAQUFBwEBBCgwJjAk" +
            "BggrBgEFBQcwAYYYaHR0cDovL29jc3AuZGlnaWNlcnQuY29tMDoGA1UdHwQzMDEwL6AtoCuGKWh0" +
            "dHA6Ly9jcmwzLmRpZ2ljZXJ0LmNvbS9PbW5pcm9vdDIwMjUuY3JsMD0GA1UdIAQ2MDQwMgYEVR0g" +
            "ADAqMCgGCCsGAQUFBwIBFhxodHRwczovL3d3dy5kaWdpY2VydC5jb20vQ1BTMA0GCSqGSIb3DQEB" +
            "CwUAA4IBAQCaY7yD314rgxSrOxvoe+rWl9p4NTvl77KN9GTnZCtwcXkHZStLBL4Iq3s7lNtEuuaC" +
            "LL1lMGw2NFJu/X4KrwjooNE37mJs/48ENE/gXHHGhg1BmWS2x28dZ297o872/7Li8DfLX8H0gr7n" +
            "vvGjaLnFcg7aUkuXnG3GmGC/64zkFnojEo+m0RBDNo8+6jIEE5SGXLrNralrjjMl1CP4m899U1ho" +
            "jARrvY5Mm3VeS2IilFsQgO5MaolAx3gR/HULerBYGhY4lJIuG0ja0Xr54BZjElGBjJCxhC4//7KO" +
            "qH5MOGr/XFwWWKiF/13Ao/ioFUCvM+wNMlIZHzIJ82U+krSEAAVYLjUwOQAAA3swggN3MIICX6AD" +
            "AgECAgQCAAC5MA0GCSqGSIb3DQEBBQUAMFoxCzAJBgNVBAYTAklFMRIwEAYDVQQKEwlCYWx0aW1v" +
            "cmUxEzARBgNVBAsTCkN5YmVyVHJ1c3QxIjAgBgNVBAMTGUJhbHRpbW9yZSBDeWJlclRydXN0IFJv" +
            "b3QwHhcNMDAwNTEyMTg0NjAwWhcNMjUwNTEyMjM1OTAwWjBaMQswCQYDVQQGEwJJRTESMBAGA1UE" +
            "ChMJQmFsdGltb3JlMRMwEQYDVQQLEwpDeWJlclRydXN0MSIwIAYDVQQDExlCYWx0aW1vcmUgQ3li" +
            "ZXJUcnVzdCBSb290MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAowS7IquYPVfoJnKa" +
            "tXnUKeLh6JWAsbDjW44rKZpk36Fd7bAJBW3bKC7OYqJi/rSI2hLrOOshncBBKwFSe4h30xyPx7q5" +
            "iLVqCedz6BFAp9HMymKNLeWPC6ZQ0qhQwyjq9aslh4qalhypZ7g/DNX3+VITL8Ib1XBw8I/AEsoG" +
            "y5rh2cozenfW+Oy58WhEQkgT0sDCpK5eYP62pgX8tN0HWQLUWRiYY/WlY+CQDH1dsgZ684Xq69QD" +
            "rl6EPl//Fe1pvPk5NnJ1z3dSTfPJkCy5PeXJI1M/HySYIVwHmSm9xjrs526GOmuXdGMzvWgYMfB4" +
            "jXa//J6OXSqGp02Q3CcaOQIDAQABo0UwQzAdBgNVHQ4EFgQU5Z1ZMIJHWMys+ghUNoZ7OrUETfAw" +
            "EgYDVR0TAQH/BAgwBgEB/wIBAzAOBgNVHQ8BAf8EBAMCAQYwDQYJKoZIhvcNAQEFBQADggEBAIUM" +
            "XY7kb1FoQgWg3btPJyWEA733ZP0t1zDjpBAX69opKbZ5P3b2GRMjuBAK+Vik1GFwvQRhahKKF9UK" +
            "vcW8MHzW6QwljYZAT+zMo344xjcRT+3daDGOTNKzAXTuvnVeB0gaf3D/FlyEwHmFuAX9f75lEaMP" +
            "wAK0+FI3OQTVqTF6GL+gKvQSmfejRYLjPF71nZ61yJ58Lsiknk4IFEtt/XBtaxpjvWTmH7fO8PKf" +
            "Lrsbt/JQiHOSwuLjFo2aMgKrjhjd6RAR7n41q5CvPjCUetAzPadlD/X8jp5iz0dELAFdux21MtJH" +
            "0jgu0P6B3DJqHrXuPNX854EdGcMkQupjOameqnqbcfg0sxg/CfaNdGkJ/od3Tw==";

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }


    @Bean
    public EmbeddedServletContainerFactory servletContainer() throws IOException {
        TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
        tomcat.addAdditionalTomcatConnectors(createSslConnector());
        return tomcat;
    }

    //开启https
    private Connector createSslConnector() throws IOException {
        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
        Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
        File keystoreFile = new File(System.getProperty("java.io.tmpdir") + File.separator + "keystore");
        FileCopyUtils.copy(Base64Utils.decodeFromString(KEYSTORE_TEST), keystoreFile);
        connector.setScheme("https");
        connector.setSecure(true);
        connector.setPort(443);
        protocol.setSSLEnabled(true);
        protocol.setKeystoreFile(keystoreFile.getAbsolutePath());
        protocol.setKeystorePass("yanghuan198887");
        protocol.setKeystoreType("JKS");
        return connector;
    }

    //文件上传配置
    @Bean
    public MultipartConfigElement multipartConfigElement() {  
        MultipartConfigFactory factory = new MultipartConfigFactory();  
        //单个文件最大  
        factory.setMaxFileSize("50MB"); //KB,MB  
        /// 设置总上传数据总大小  
        factory.setMaxRequestSize("50MB");  
        return factory.createMultipartConfig();  
    } 
}

